package org.jetnuke.modules.download;

import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.DownloadsModRequest;
import org.jetnuke.util.JetUtil;

public class ModifyDownloadRequest implements IAction {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(ModifyDownloadRequest.class);

	int id;

	String title, name, url, description, email, version, homepage;

	int cat;

	int filesize;

	public void setEmail(String email) {
		this.email = email;
	}

	public void setFilesize(int filesize) {
		this.filesize = filesize;
	}

	public void setHomepage(String homepage) {
		this.homepage = homepage;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public void setCat(int cat) {
		this.cat = cat;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.common.IAction#exec(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse,
	 *      org.apache.velocity.VelocityContext, org.jetnuke.common.IModuleInfo,
	 *      java.lang.String, org.jetnuke.common.IUserInfo,
	 *      org.jetnuke.common.IAdminInfo)
	 */
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		if (logger.isDebugEnabled()) {
			logger
					.debug("exec(HttpServletRequest, HttpServletResponse, VelocityContext, IModuleInfo, String, IUserInfo, IAdminInfo) - start"); //$NON-NLS-1$
		}

		DownloadsModRequest modRequest = new DownloadsModRequest();
		// downloads_modrequest modRequest = new downloads_modrequest();
		modRequest.setLID(id);
		modRequest.setDESCRIPTION(description);
		modRequest.setTITLE(title);
		modRequest.setURL(url);
		modRequest.setCID(cat);
		String user = "";
		if (ui != null)
			user = ui.getUname();
		modRequest.setMODIFYSUBMITTER(user);
		modRequest.setNAME(name);
		modRequest.setBROKENDOWNLOAD(0);
		modRequest.setFILESIZE(filesize);
		modRequest.setHOMEPAGE(homepage);
		modRequest.setVERSION(version);
		modRequest.setEMAIL(email);
		DataAccessDriver.getInst().newDownloadModRequestDAO()
				.addNew(modRequest);
		// modRequest.save();
		JetUtil.redirect(vc, response, request.getContextPath()
				+ "/do/download/mod_requested");

		if (logger.isDebugEnabled()) {
			logger
					.debug("exec(HttpServletRequest, HttpServletResponse, VelocityContext, IModuleInfo, String, IUserInfo, IAdminInfo) - end"); //$NON-NLS-1$
		}
		return null;
	}

}
